//
//  MyInfoDetailViewController.m
//  时尚男士
//
//  Created by 张家为 on 15/6/9.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "MyInfoDetailViewController.h"
#import "UIImageView+WebCache.h"
#import "myView.h"
#import "Photo.h"
#import "InfoDetailController.h"
#import "InfoPhotoViewController.h"
#import "InformationViewController.h"
#define Width self.view.frame.size.width
#define Height self.view.frame.size.height
#define BW Width/ 1080 * 624
@interface MyInfoDetailViewController ()
@property (nonatomic, retain)UIImageView *BannerImageView;
@property (nonatomic, retain)myView *Myview;
@property (nonatomic, retain)myView *Myvie2;
@property (nonatomic, retain)myView *Myview3;
@property (nonatomic, retain)UILabel *threeTitleLabel;
@property (nonatomic, retain)UIImageView *smallview;
@property (nonatomic, retain)UIImageView *smallview2;
@property (nonatomic, retain)UIImageView *smallview3;
@property (nonatomic, retain)myView *Myview4;
@property (nonatomic, retain)myView *Myvie5;
@property (nonatomic, retain)myView *Myview6;
@property (nonatomic, retain)UILabel *threeTitleLabel2;
@property (nonatomic, retain)UIImageView *smallview4;
@property (nonatomic, retain)UIImageView *smallview5;
@property (nonatomic, retain)UIImageView *smallview6;


@property (nonatomic, retain)NSMutableArray *titleArr;
@property (nonatomic, retain)NSMutableArray *imagesArr;
@property (nonatomic, retain)NSMutableArray *myarr;
@property (nonatomic, retain)NSMutableArray *dicArr;
@property (nonatomic, retain)NSMutableArray *smallArr;

@end

@implementation MyInfoDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.smallArr = [NSMutableArray array];
    self.dicArr = [NSMutableArray array];
    self.imagesArr = [NSMutableArray array];
    self.titleArr = [NSMutableArray array];
    self.myarr = [NSMutableArray array];
    UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, Width, Height)];
    scrollview.contentSize = CGSizeMake(0, Height * 2- 40);
    [self.view addSubview:scrollview];
    [self connectionStr:@"http://c.m.163.com/nc/article/list/T1348650593803/0-60.html"];
    // Do any additional setup after loading the view.
    self.BannerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, Width, BW)];
    self.BannerImageView.userInteractionEnabled = YES;
    [scrollview addSubview:self.BannerImageView];
    UITapGestureRecognizer *bannerTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.BannerImageView addGestureRecognizer:bannerTap];
    [self.BannerImageView release];
    [bannerTap release];
    
    self.Myview = [[myView alloc] initWithFrame:CGRectMake(0, BW + 10, Width, 80)];
    [scrollview addSubview:self.Myview];
    UITapGestureRecognizer *MYviewTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.Myview addGestureRecognizer:MYviewTap];
    [_Myview release];
    [MYviewTap release];
    
    self.Myvie2 = [[myView alloc] initWithFrame:CGRectMake(0, BW + 100, Width, 80)];
    [scrollview addSubview:self.Myvie2];
    UITapGestureRecognizer *MYvie2Tap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.Myvie2 addGestureRecognizer:MYvie2Tap];
    [_Myvie2 release];
    [MYvie2Tap release];
    
    self.Myview3 = [[myView alloc] initWithFrame:CGRectMake(0, BW + 190, Width, 80)];
    UITapGestureRecognizer *MYview3Tap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.Myview3 addGestureRecognizer:MYview3Tap];
    [scrollview addSubview:self.Myview3];
    [_Myview3 release];
    [MYview3Tap release];
    
    self.threeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, BW + 280, Width, 10)];
    [scrollview addSubview:self.threeTitleLabel];
    [_threeTitleLabel release];
    
    self.smallview = [[UIImageView alloc] initWithFrame:CGRectMake(10, BW + 300, (Width - 40) / 3, 80)];
    self.smallview.userInteractionEnabled = YES;
    UITapGestureRecognizer *smallTap  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.smallview addGestureRecognizer:smallTap];
    [scrollview addSubview:self.smallview];
    [_smallview release];
    [smallTap release];
    
    self.smallview2 = [[UIImageView alloc] initWithFrame:CGRectMake(20 + (Width - 40) / 3, BW + 300, (Width - 40) / 3, 80)];
    [scrollview addSubview:self.smallview2];
    self.smallview2.userInteractionEnabled = YES;
    UITapGestureRecognizer *smallTap2  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.smallview2 addGestureRecognizer:smallTap2];
    [smallTap2 release];
    [_smallview2 release];
    
    self.smallview3 = [[UIImageView alloc] initWithFrame:CGRectMake(30 + (Width - 40) / 3 * 2, BW + 300, (Width - 40) / 3, 80)];
    [scrollview addSubview:self.smallview3];
    self.smallview3.userInteractionEnabled = YES;
    UITapGestureRecognizer *smallTap3  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.smallview3 addGestureRecognizer:smallTap3];
    [smallTap3 release];
    [_smallview3 release];
    
    self.Myview4 = [[myView alloc] initWithFrame:CGRectMake(0, BW + 390, Width, 80)];   
    
    [scrollview addSubview:self.Myview4];
    UITapGestureRecognizer *myView4Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.Myview4 addGestureRecognizer:myView4Tap];
    [myView4Tap release];
    [_Myview4 release];
    
    self.Myvie5 = [[myView alloc] initWithFrame:CGRectMake(0, BW + 480, Width, 80)];
    UITapGestureRecognizer *myView5Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.Myvie5 addGestureRecognizer:myView5Tap];
    [myView5Tap release];
    [scrollview addSubview:self.Myvie5];
    [_Myvie5 release];
    
    self.Myview6 = [[myView alloc] initWithFrame:CGRectMake(0, BW + 570, Width, 80)];
    [scrollview addSubview:self.Myview6];
    UITapGestureRecognizer *myView6Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.Myview6 addGestureRecognizer:myView6Tap];
    [myView6Tap release];
    [_Myview6 release];
    
    self.threeTitleLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(0, BW + 660, Width, 10)];
    [scrollview addSubview:self.threeTitleLabel2];
    [_threeTitleLabel2 release];
    
    self.smallview4 = [[UIImageView alloc] initWithFrame:CGRectMake(10, BW + 680, (Width - 40) / 3, 80)];
    [scrollview addSubview:self.smallview4];
    self.smallview4.userInteractionEnabled = YES;
    UITapGestureRecognizer *smallTap4  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.smallview4 addGestureRecognizer:smallTap4];
    [smallTap4 release];
    [_smallview4 release];
    
    self.smallview5 = [[UIImageView alloc] initWithFrame:CGRectMake(20 + (Width - 40) / 3, BW + 680, (Width - 40) / 3, 80)];
    [scrollview addSubview:self.smallview5];
    self.smallview5.userInteractionEnabled = YES;
    UITapGestureRecognizer *smallTap5  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.smallview5 addGestureRecognizer:smallTap5];
    [smallTap5 release];
    [_smallview5 release];
    
    self.smallview6 = [[UIImageView alloc] initWithFrame:CGRectMake(30 + (Width - 40) / 3 * 2, BW + 680, (Width - 40) / 3, 80)];
    [scrollview addSubview:self.smallview6];
    self.smallview6.userInteractionEnabled = YES;
    UITapGestureRecognizer *smallTap6  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.smallview6 addGestureRecognizer:smallTap6];
    [smallTap6 release];

    [_smallview6 release];
    
    UIButton *zhuantiButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [scrollview addSubview:zhuantiButton];
    [zhuantiButton setTitle:@"进入专题" forState:UIControlStateNormal];
    [zhuantiButton setTintColor:[UIColor redColor]];
    zhuantiButton.frame = CGRectMake(Width - 60, BW + 770, 60, 40);
    [zhuantiButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

    
    [scrollview release];
   
}

- (void)buttonAction:(UIButton *)myButton{
        
    //专题页改成informationViewController
    InformationViewController *informationVC = [[InformationViewController alloc] init];
    [self.navigationController pushViewController:informationVC animated:YES];
    [informationVC release];
}


- (void)tapAction:(UITapGestureRecognizer *)tap{

    InfoDetailController *myInfo = [[InfoDetailController alloc] init];
    NSString *str = nil;
    if (tap.view == self.Myview) {
    str = [[self.dicArr objectAtIndex:1] objectForKey:@"url_3w"];
        myInfo.Docid = str;
        [self.navigationController pushViewController:myInfo animated:NO];
    }
    if (tap.view == self.Myvie2){
        str = [[self.dicArr objectAtIndex:2] objectForKey:@"url_3w"];
        myInfo.Docid = str;
        [self.navigationController pushViewController:myInfo animated:NO];
    }
    if (tap.view == self.Myview3) {
        str = [[self.dicArr objectAtIndex:3] objectForKey:@"url_3w"];
        myInfo.Docid = str;
        [self.navigationController pushViewController:myInfo animated:NO];
    }
    if (tap.view == self.Myview4) {
        str = [[self.dicArr objectAtIndex:4] objectForKey:@"url_3w"];
        myInfo.Docid = str;
        [self.navigationController pushViewController:myInfo animated:NO];
    }
    if (tap.view == self.Myvie5) {
         str = [[self.dicArr objectAtIndex:5] objectForKey:@"url_3w"];
        myInfo.Docid = str;
        [self.navigationController pushViewController:myInfo animated:NO];
    }
    if (tap.view == self.Myview6) {
        str = [[self.dicArr objectAtIndex:6] objectForKey:@"url_3w"];
        [self.navigationController pushViewController:myInfo animated:NO];
    }
    if (tap.view == self.smallview || tap.view == self.smallview2 || tap.view == self.smallview3) {
        Photo *photo = [[Photo alloc] init];

        [self.navigationController pushViewController:photo animated:NO];
        NSMutableArray *arr = [NSMutableArray arrayWithArray:[[self.smallArr objectAtIndex:0] objectForKey:@"imgextra"]];
      [arr addObject: [[self.smallArr objectAtIndex:0] objectForKey:@"imgsrc"]];
        photo.photoImg1 = [[arr objectAtIndex:0] objectForKey:@"imgsrc"];
        photo.photoImg2 = [[arr objectAtIndex:1] objectForKey:@"imgsrc"];
        photo.photoUrl = [arr objectAtIndex:2];
        [photo release];
    }
    if (tap.view == self.smallview4 || tap.view == self.smallview5 || tap.view == self.smallview6) {
        Photo *photo = [[Photo alloc] init];
        NSMutableArray *arr1 = [NSMutableArray arrayWithArray:[[self.smallArr objectAtIndex:0] objectForKey:@"imgextra"]];
        [arr1 addObject: [[self.smallArr objectAtIndex:1] objectForKey:@"imgsrc"]];
        photo.photoImg1 = [[arr1 objectAtIndex:0] objectForKey:@"imgsrc"];
        photo.photoImg2 = [[arr1 objectAtIndex:1] objectForKey:@"imgsrc"];
        photo.photoUrl = [arr1 objectAtIndex:2];
        [self.navigationController pushViewController:photo animated:NO];
        [photo release];
        NSLog(@"点击");
    }


}
- (void)DataprocessingDic:(id)myData{
  NSString *image =  [[[myData objectForKey:@"T1348650593803"] objectAtIndex:0] objectForKey:@"imgsrc"];
    [self.BannerImageView setImageWithURLStr:image];
    NSMutableArray *arr = [myData objectForKey:@"T1348650593803"];
    for (NSMutableDictionary *dic in arr) {
        NSString *str = [dic objectForKey:@"docid"];
        if (str.length == 16) {
            [self.dicArr addObject:dic];
        }
    }

    NSString *imageViewStr = [[self.dicArr objectAtIndex:1] objectForKey:@"imgsrc"];
    [self.Myview.imageView setImageWithURLStr:imageViewStr];

    self.Myview.TitleLable.text = [[self.dicArr objectAtIndex:1] objectForKey:@"title"];
    self.Myview.lable.text = [[self.dicArr objectAtIndex:1] objectForKey:@"digest"];
    
    imageViewStr = [[self.dicArr objectAtIndex:2] objectForKey:@"imgsrc"];
    [self.Myvie2.imageView setImageWithURLStr:imageViewStr];
    self.Myvie2.TitleLable.text = [[self.dicArr objectAtIndex:2] objectForKey:@"title"];
    self.Myvie2.lable.text = [[self.dicArr objectAtIndex:2] objectForKey:@"digest"];
    
    imageViewStr = [[self.dicArr objectAtIndex:3] objectForKey:@"imgsrc"];
    [self.Myview3.imageView setImageWithURLStr:imageViewStr];
    self.Myview3.TitleLable.text = [[self.dicArr objectAtIndex:3] objectForKey:@"title"];
    self.Myview3.lable.text = [[self.dicArr objectAtIndex:3] objectForKey:@"digest"];
    
    
    
    imageViewStr = [[self.dicArr objectAtIndex:4] objectForKey:@"imgsrc"];
    [self.Myview4.imageView setImageWithURLStr:imageViewStr];
    self.Myview4.TitleLable.text = [[self.dicArr objectAtIndex:4] objectForKey:@"title"];
    [self.Myview4.imageView setImageWithURLStr:imageViewStr];
    self.Myview4.lable.text = [[self.dicArr objectAtIndex:4] objectForKey:@"digest"];
    

    
    imageViewStr = [[self.dicArr objectAtIndex:5] objectForKey:@"imgsrc"];
    [self.Myvie5.imageView setImageWithURLStr:imageViewStr];
    self.Myvie5.TitleLable.text = [[self.dicArr objectAtIndex:5] objectForKey:@"title"];
    self.Myvie5.lable.text = [[self.dicArr objectAtIndex:5] objectForKey:@"digest"];
    
    imageViewStr = [[self.dicArr objectAtIndex:6] objectForKey:@"imgsrc"];
    [self.Myview6.imageView setImageWithURLStr:imageViewStr];
    self.Myview6.TitleLable.text = [[self.dicArr objectAtIndex:6] objectForKey:@"title"];
    self.Myview6.lable.text = [[self.dicArr objectAtIndex:6] objectForKey:@"digest"];
    
    

    for (NSMutableDictionary *dic in arr) {
        if ([dic objectForKey:@"imgextra"] != nil) {
            NSString *title = [dic objectForKey:@"title"];
            [self.titleArr addObject:title];
            NSMutableArray *arr1 = [dic objectForKey:@"imgextra"];
            [self.imagesArr addObject:arr1];
            NSString *url = [dic objectForKey:@"imgsrc"];
            [self.myarr addObject:url];
            [self.smallArr addObject:dic];
        }
    }
    
    self.threeTitleLabel.text = [self.titleArr objectAtIndex:2];
    
    imageViewStr = [[[self.imagesArr objectAtIndex:2] objectAtIndex:0] objectForKey:@"imgsrc"];
    [self.smallview setImageWithURLStr:imageViewStr];
    
    imageViewStr = [[[self.imagesArr objectAtIndex:2] objectAtIndex:1] objectForKey:@"imgsrc"];
    
    [self.smallview2 setImageWithURLStr:imageViewStr];
    
    imageViewStr = [self.myarr objectAtIndex:2];
    
    [self.smallview3 setImageWithURLStr:imageViewStr];
    
    
    
    self.threeTitleLabel2.text = [self.titleArr objectAtIndex:1];
    imageViewStr = [[[self.imagesArr objectAtIndex:1] objectAtIndex:0] objectForKey:@"imgsrc"];
    [self.smallview4 setImageWithURLStr:imageViewStr];
    
    imageViewStr = [[[self.imagesArr objectAtIndex:1] objectAtIndex:1] objectForKey:@"imgsrc"];
    
    [self.smallview5 setImageWithURLStr:imageViewStr];
    

    imageViewStr = [self.myarr objectAtIndex:1];

    [self.smallview6 setImageWithURLStr:imageViewStr];
    

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
